<template>
  <div class="accountInfo-1123">
    <h2 class="title">账户信息</h2>
    <div class="account-info-box flex jc-c">
      <div class="left-img-box">
        <img class="left-head-img" :src="fileList[0].url | nopic" />
        <a class="modify-head-btn">
          <el-upload
            class="upload-demo"
            ref="upload"
            action="https://mall.jmmc.com.cn/prod/mall-portal/api/file/upload"
            :on-remove="handleRemove"
            :on-change="handleChange"
            :file-list="fileList"
            :headers="myHeaders"
            :show-file-list="false"
            list-type="picture"
          >
            <el-button size="small" type="primary">修改头像</el-button>
            <!--<div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>-->
          </el-upload></a
        >
      </div>

      <div class="right-info-box">
        <el-form
          :label-position="labelPosition"
          label-width="80px"
          :model="accounInfoObj"
        >
          <div class="inner-border-box">
            <el-form-item label="用户ID">
              <span>{{ accounInfoObj.id }}</span>
            </el-form-item>
            <el-form-item label="会员类型">
              <span class="user-type">普通会员</span>
            </el-form-item>
            <el-form-item label="用户名称">
              <el-input
                class="user-info"
                v-model="accounInfoObj.nickname"
              ></el-input>
            </el-form-item>
            <el-form-item label="出生日期">
              <el-date-picker
                v-model="accounInfoObj.birthday"
                type="date"
                placeholder="选择日期"
                format="yyyy/MM/dd"
                value-format="timestamp"
              >
              </el-date-picker>
              <!--<el-input  class="user-info"  v-model="accounInfoObj.birthday"></el-input>-->
            </el-form-item>
            <el-form-item label="性别">
              <el-select
                class="user-info"
                v-model="accounInfoObj.gender"
                placeholder="请选择活动性别"
              >
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </div>
          <el-form-item>
            <el-button type="danger" @click="updateUserInfo">保存</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "AccountInfo",
  components: {},
  data() {
    return {
      myHeaders: { Authorization: localStorage.getItem("token") },
      labelPosition: "left",
      accounInfoObj: {
        name: "",
        region: "",
        type: "",
      },
      fileList: [],
      options: [
        {
          value: 1,
          label: "男",
        },
        {
          value: 0,
          label: "女",
        },
      ],
    };
  },
  methods: {
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file);
    },
    handleChange(file, fileList) {
      // console.log("这是file", file);
      // console.log("这是fileList", fileList);
      // 当多余一个的时候替换文件
      if (fileList.length > 1) {
        fileList.splice(0, 1);
      }
    },
    updateUserInfo() {
      let data = {
        nickname: this.accounInfoObj.nickname,
        birthday:this.accounInfoObj.birthday,
        id: this.accounInfoObj.id,
        gender: this.accounInfoObj.gender,
      };

      this.$http.post("/sso/member", data).then((response) => {
        localStorage.setItem("userinfo", JSON.stringify(this.accounInfoObj));
        this.$message({
          showClose: true,
          message: response.message,
          type: "success",
        });
      });
    },
    unicToDate(unixTime, isFull, timeZone) {
      if (typeof timeZone == "number") {
        unixTime = parseInt(unixTime) + parseInt(timeZone) * 60 * 60;
      }
      var time = new Date(unixTime * 1000);
      var ymdhis = "";
      ymdhis += time.getUTCFullYear() + "-";
      ymdhis += time.getUTCMonth() + 1 + "-";
      ymdhis += time.getUTCDate();
      if (isFull === true) {
        ymdhis += " " + time.getUTCHours() + ":";
        ymdhis += time.getUTCMinutes() + ":";
        ymdhis += time.getUTCSeconds();
      }
      return ymdhis;
    },
  },
  created() {
    this.accounInfoObj = JSON.parse(localStorage.getItem("userinfo"));
    this.fileList.push({
      name: "1",
      url: this.accounInfoObj.cardpic,
    });
     // this.accounInfoObj.birthday =this.accounInfoObj.birthday;
    window.console.log(this.accounInfoObj);
  },
};
</script>

<style lang="scss" >
.el-upload-list {
  display: none;
}
.accountInfo-1123 {
  .title {
    font-weight: normal;
    text-align: left;
    height: 28px;
    font-size: 28px;
    line-height: 28px;
    color: #757575;
    padding: 30px 0 0 33px;
  }
  .account-info-box {
    padding: 50px 0;
    .left-img-box {
      .left-head-img {
        width: 114px;
        height: 114px;
        border-radius: 50%;
      }
      .modify-head-btn {
        display: block;
        height: 12px;
        font-size: 14px;
        line-height: 12px;
        margin-top: 10px;
        color: #cf2626;
        cursor: pointer;
      }
    }

    .right-info-box {
      .inner-border-box {
        text-align: left;
        border-left: 1px solid #dcdcdc;
        margin-left: 41px;
        padding-left: 30px;
        .user-info {
          width: 360px;
        }
      }
    }
  }
}
/*手机端*/
@media (min-width: 320px) and (max-width: 800px) {

    .accountInfo-1123 {
      .title {
        font-size: 18px;
        padding: 10px 0 0 20px;
      }
      .account-info-box.flex {
        display: block;
        padding: 5px 0;
        .right-info-box{
          margin-top: 30px;
          .inner-border-box{
            margin-left: 0;
            padding-left: 20px;
             .user-info{
               width: 70%;
             }
          }
            .el-form-item__content{
               margin-left: 0 !important;
             }
        }
      }
    
    }
 
}
</style>